<template>
    <div>
        <div ref="warp" class="container"></div>
    </div>
</template>

<script>
import { posroom } from '@/api/pos.js';

import echarts from 'echarts';

export default {
    data() {
        return {
            dataService:[],
            dataGoods:[]
        };
    },
    mounted() {
        this.showChart();
    },
    methods: {
        showChart() {
            let myChart = echarts.init(this.$refs.warp);
            posroom().then(res => {
                this.dataService = res.dataService;
                this.dataGoods = res.dataGoods;
                myChart.setOption(this.posOptions, true);
            });
        }
    },
    computed: {
        posOptions() {
            return {
                title: {
                    text: '销售额统计'
                },
                legend: {
                    data: ['服务销售额', '门店销售额']
                },
                tooltip: {},
                xAxis: {
                    type: 'category',
                    data: ['2012', '2013', '2014', '2015', '2016']
                },
                yAxis: {
                    type:"value"
                },
                series: [
                    {
                        name: '服务销售额',
                        type: 'bar',
                        data: this.dataService
                    },
                    {
                        name: '门店销售额',
                        type: 'bar',
                        data: this.dataGoods
                    },
                ]
            };
        }
    }
};
</script>

<style>
.container {
    width: 1000px;
    height: 500px;
    margin: auto;
}
</style>